package com.leoman.controller.api;

import com.leoman.core.ErrorType;
import com.leoman.core.bean.Result;
import com.leoman.entity.*;
import com.leoman.entity.vo.UserInfoVo;
import com.leoman.exception.*;
import com.leoman.service.*;
import com.leoman.utils.JsonUtil;
import com.leoman.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户api
 * Created by 涂奕恒 on 2016/11/28 0018.
 */
@Controller
@RequestMapping(value = "api/user")
public class UserApi {

    @Autowired
    private UserService userService;

    @Autowired
    private UserTagService userTagService;

    @Autowired
    private UserAddressService userAddressService;

    @Autowired
    private AttentionService attentionService;

    @Autowired
    private LeaveMessageService leaveMessageService;

    @Autowired
    private CommentService commentService;

    @Autowired
    private PaperService paperService;

    @Autowired
    private BroadcastService broadcastService;

    @Autowired
    private MindService mindService;

    @Autowired
    private CircleService circleService;

    @Autowired
    private LetterService letterService;

    /**
     * @api {post} /api/user/info 1、用户详情
     * @apiVersion 0.0.1
     * @apiName user.info
     * @apiGroup user
     *
     * @apiDescription 用户详情
     *
     * @apiParam   {Integer}  userId                    用户ID            (必填)
     *
     * @apiSuccess {Object}   userInfo
     * @apiSuccess {Integer}  userInfo.id               id
     * @apiSuccess {String}   userInfo.nickName         昵称
     * @apiSuccess {String}   userInfo.avatar           头像
     * @apiSuccess {String}   userInfo.mobile           手机
     * @apiSuccess {Integer}  userInfo.sex              性别
     * @apiSuccess {Integer}  userInfo.age              年龄
     * @apiSuccess {Integer}  userInfo.fansNum          粉丝数
     * @apiSuccess {Integer}  userInfo.attentionNum     关注数
     * @apiSuccess {Integer}  userInfo.leaveNum         留言数
     * @apiSuccess {Integer}  userInfo.regionId         所在区域ID
     * @apiSuccess {String}   userInfo.email            电子邮箱
     * @apiSuccess {Integer}  userInfo.money            账户余额
     * @apiSuccess {String}   userInfo.aliPayName       支付宝用户名
     * @apiSuccess {String}   userInfo.aliPayAccount    支付宝账号
     * @apiSuccess {Integer}  userInfo.isBindingWeiXin  是否绑定微信，0=否，1=是
     * @apiSuccess {Integer}  userInfo.isBindingWeiBo   是否绑定微博，0=否，1=是
     * @apiSuccess {Integer}  userInfo.isBindingQQ      是否绑定QQ，0=否，1=是
     * @apiSuccess {Integer}  userInfo.isNewFans        是否有新的粉丝，0=否，大于0=是
     * @apiSuccess {Integer}  userInfo.isNewAttention   是否有新的关注，0=否，大于0=是
     * @apiSuccess {Integer}  userInfo.isNewLeave       是否有新的留言，0=否，大于0=是
     * @apiSuccess {String}   userInfo.createTime       注册时间
     * @apiSuccess {String}   userInfo.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "userInfo": {
     *              "id": 14,
     *              "nickName": "老大",
     *              "avatar": "",
     *              "mobile": "13872116519",
     *              "sex": 0,
     *              "age": 0,
     *              "regionId": "",
     *              "email": "",
     *              "money": 0,
     *              "aliPayName": "",
     *              "aliPayAccount": "",
     *              "createTime": "1474600084564",
     *              "updateTime": "1474600084564"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public void info(HttpServletResponse response, Integer userId) {
        try {
            User user = userService.iFindOneByInfo(userId);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successInfoApi(user, "userInfo"), "password", "type", "region"));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/modifyInfo 2、修改用户信息
     * @apiVersion 0.0.1
     * @apiName user.modifyInfo
     * @apiGroup user
     *
     * @apiDescription 修改用户信息
     *
     * @apiParam   {Integer}  userId                    用户ID          (必填)
     * @apiParam   {String}   nickName                  昵称
     * @apiParam   {String}   birthday                  生日
     * @apiParam   {Integer}  sex                       性别 0=男，1=女
     * @apiParam   {Integer}  regionId                  所在区域ID
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/modifyInfo", method = RequestMethod.POST)
    public void modifyInfo(HttpServletResponse response, Integer userId, String nickName, String birthday, Integer sex, Integer regionId) {
        try {
            userService.iModifyUserInfo(userId, nickName, birthday, sex, regionId);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/modifyPassword 3、修改用户密码
     * @apiVersion 0.0.1
     * @apiName user.modifyPassword
     * @apiGroup user
     *
     * @apiDescription 修改用户密码
     *
     * @apiParam   {Integer}  userId                    用户ID          (必填)
     * @apiParam   {String}   oldPassword               旧密码          (必填)
     * @apiParam   {String}   newPassword               新密码          (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     *      }
     * }
     */
    @RequestMapping(value = "/modifyPassword", method = RequestMethod.POST)
    public void modifyPassword(HttpServletResponse response, Integer userId, String oldPassword, String newPassword) {
        try {
            userService.iModifyUserPassword(userId, oldPassword, newPassword);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (OldPasswordErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_OLD_PASSWORD_ERROR));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/modifyAvatar 4、修改用户头像
     * @apiVersion 0.0.1
     * @apiName user.modifyAvatar
     * @apiGroup user
     *
     * @apiDescription 修改用户头像
     *
     * @apiParam   {Integer}  userId                    用户ID          (必填)
     * @apiParam   {Stream}   avatar                    头像文件        (必填)
     * @apiParam   {Stream}   backgroundImage           背景文件        (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     *      }
     * }
     */
    @RequestMapping(value = "/modifyAvatar", method = RequestMethod.POST)
    public void modifyAvatar(HttpServletResponse response, Integer userId, MultipartRequest multipartRequest) {
        try {
            userService.iModifyUserAvatar(userId, multipartRequest);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/applyMoney 5、用户申请提现
     * @apiVersion 0.0.1
     * @apiName user.applyMoney
     * @apiGroup user
     *
     * @apiDescription 用户申请提现
     *
     * @apiParam   {Integer}  userId                    用户ID          (必填)
     * @apiParam   {String}   account                   支付宝账户       (必填)
     * @apiParam   {Double}   money                     提现金额        (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     *      }
     * }
     */
    @RequestMapping(value = "/applyMoney", method = RequestMethod.POST)
    public void applyMoney(HttpServletResponse response, Integer userId, Double money, String account) {
        try {
            userService.iApplyMoney(userId, money, account);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (MoneyShortException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MONEY_SHORT));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (ApplyMoneyCountMaxException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_APPLY_MONEY_COUNT_MAX));
        } catch (CreateTimeShortException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CREATE_TIME_SHORT));
        }
    }

    /**
     * @api {post} /api/user/tag/list 6、标签列表
     * @apiVersion 0.0.1
     * @apiName user.tagList
     * @apiGroup user
     *
     * @apiDescription 标签列表
     *
     * @apiParam   {Integer}   userId                     用户Id      （必填）
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    标签ID
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {Integer}   list.isDefault             是否默认标签，0=否，1=是
     * @apiSuccess {Integer}   list.updateNum             修改次数，默认标签的修改次数为1时，代表已达上限，无法再被修改
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "content" : "鲜花"
     *              },
     *              {
     *                  "id" : 4,
     *                  "content" : "夏日"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/tag/list", method = RequestMethod.POST)
    public void tagList(HttpServletResponse response, Integer userId) {
        if (null == userId) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        List<UserTag> list = userTagService.findListByUserId(userId);
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list), "user");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/tag/modify 7、修改标签
     * @apiVersion 0.0.1
     * @apiName user.modifyTag
     * @apiGroup user
     *
     * @apiDescription 修改标签
     *
     * @apiParam   {Integer}   userId                     用户Id                                                                      （必填）
     * @apiParam   {String}    tagIds                     标签Id，中间用英文逗号隔开，第一个是鲜花和绿草的id中的一个，顺序不要弄错了         （必填）
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/tag/modify", method = RequestMethod.POST)
    public void modifyTag(HttpServletResponse response, Integer userId, String tagIds) {
        try {
            userTagService.iModifyInfo(userId, tagIds);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (TagNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_TAG_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (UpdateNumMaxException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_UPDATE_NUM_MAX));
        }
    }

    /**
     * @api {post} /api/user/bindingInfo 8、绑定第三方信息
     * @apiVersion 0.0.1
     * @apiName user.bindingInfo
     * @apiGroup user
     *
     * @apiDescription 绑定第三方信息
     *
     * @apiParam   {Integer}   userId                    用户Id                                 (必填)
     * @apiParam   {String}    openId                    唯一标识                                (必填)
     * @apiParam   {Integer}   type                      类型，1=QQ，2=微信，3=微博               (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/bindingInfo", method = RequestMethod.POST)
    public void bindingInfo(HttpServletResponse response, Integer userId, Integer type, String openId) {
        try {
            userService.iBindingInfo(userId, type, openId);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (ThirdExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_THIRD_INFO_EXIST));
        }
    }

    /**
     * @api {post} /api/user/address/list 9、收货地址列表
     * @apiVersion 0.0.1
     * @apiName user.addressList
     * @apiGroup user
     *
     * @apiDescription 地址列表
     *
     * @apiParam   {Integer}   userId                     用户Id                   （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    地址ID
     * @apiSuccess {String}    list.userName              姓名
     * @apiSuccess {String}    list.mobile                手机号
     * @apiSuccess {Integer}   list.regionId              所在地ID
     * @apiSuccess {Integer}   list.regionInfo            所在地名称
     * @apiSuccess {String}    list.description           详细地址
     * @apiSuccess {Integer}   list.isDefault             是否默认地址，0=否，1=是
     * @apiSuccess {Integer}   list.createNum             创建时间
     * @apiSuccess {Integer}   list.updateNum             修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "userName" : "霍尊",
     *                  "mobile" : "15963665254",
     *                  "regionId" : 1,
     *                  "regionInfo" : "北京",
     *                  "description" : "东大街6305号",
     *                  "isDefault" : 1,
     *                  "createTime" : "1476843673494",
     *                  "updateNum" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/address/list", method = RequestMethod.POST)
    public void addressList(HttpServletResponse response, Integer userId, Integer pageNum, Integer pageSize) {
        if (null == userId) {
            String result = JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM));
            WebUtil.printApi(response, result);
            return;
        }

        Page<UserAddress> page = userAddressService.iPageByUserId(userId, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "user", "region");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/address/save 10、添加or修改收货地址
     * @apiVersion 0.0.1
     * @apiName user.saveAddress
     * @apiGroup user
     *
     * @apiDescription 绑定第三方信息
     *
     * @apiParam   {Integer}   userId                    用户Id                                 (必填)
     * @apiParam   {Integer}   addressId                 收货地址ID
     * @apiParam   {String}    userName                  姓名                                   (必填)
     * @apiParam   {String}    mobile                    手机号                                 (必填)
     * @apiParam   {Integer}   regionId                  所在地ID                               (必填)
     * @apiParam   {String}    description               详细地址                               (必填)
     * @apiParam   {Integer}   isDefault                 是否默认地址，0=否，1=是
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/address/save", method = RequestMethod.POST)
    public void saveAddress(HttpServletResponse response, Integer userId, Integer addressId, String userName, String mobile, Integer regionId, String description, Integer isDefault) {
        try {
            userAddressService.iAddAddressInfo(userId, addressId, userName, mobile, regionId, description, isDefault);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/address/delete 11、删除收货地址
     * @apiVersion 0.0.1
     * @apiName user.deleteAddress
     * @apiGroup user
     *
     * @apiDescription 绑定第三方信息
     *
     * @apiParam   {Integer}   addressId                 收货地址ID                              (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/address/delete", method = RequestMethod.POST)
    public void deleteAddress(HttpServletResponse response, Integer addressId) {
        try {
            userAddressService.iDeleteAddressInfo(addressId);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (AddressNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_ADDRESS_NOT_FIND));
        }
    }

    /**
     * @api {post} /api/user/attentionList 12、粉丝列表or关注列表
     * @apiVersion 0.0.1
     * @apiName user.attentionList
     * @apiGroup user
     *
     * @apiDescription 粉丝列表or关注列表
     *
     * @apiParam   {Integer}   userId                     用户Id                       （必填）
     * @apiParam   {Integer}   type                       类型，1=粉丝列表，2=关注列表   （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    用户ID
     * @apiSuccess {String}    list.nickName              姓名
     * @apiSuccess {String}    list.avatar                手机号
     * @apiSuccess {Integer}   list.regionId              所在地ID
     * @apiSuccess {String}    list.regionInfo            所在地名称
     * @apiSuccess {Integer}   list.isAttentionOther      我是否关注对方，0=否，1=是
     * @apiSuccess {Integer}   list.isAttentionMe         对方是否关注我，0=否，1=是
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "nickName" : "霍尊",
     *                  "avatar" : "http://www.qq.com",
     *                  "regionId" : 1,
     *                  "regionInfo" : "北京",
     *                  "isAttentionOther" : 0,
     *                  "isAttentionMe" : 0
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/attentionList", method = RequestMethod.POST)
    public void attentionList(HttpServletResponse response, Integer userId, Integer type, Integer pageNum, Integer pageSize) {
        if (null == userId || null == type) {
            String result = JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM));
            WebUtil.printApi(response, result);
            return;
        }

        Page<UserInfoVo> page = attentionService.iPageByParams(userId, type, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/attentionRandomList 13、随机三个没有互相关注的用户信息
     * @apiVersion 0.0.1
     * @apiName user.attentionRandomList
     * @apiGroup user
     *
     * @apiDescription 随机三个没有互相关注的用户信息
     *
     * @apiParam   {Integer}   userId                     用户Id                       （必填）
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    用户ID
     * @apiSuccess {String}    list.nickName              姓名
     * @apiSuccess {String}    list.avatar                手机号
     * @apiSuccess {Integer}   list.regionId              所在地ID
     * @apiSuccess {String}    list.regionInfo            所在地名称
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "nickName" : "霍尊",
     *                  "avatar" : "http://www.qq.com",
     *                  "regionId" : 1,
     *                  "regionInfo" : "北京"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/attentionRandomList", method = RequestMethod.POST)
    public void attentionRandomList(HttpServletResponse response, Integer userId) {
        if (null == userId) {
            String result = JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM));
            WebUtil.printApi(response, result);
            return;
        }

        List<UserInfoVo> list = attentionService.findThreeUserInfo(userId);
        while (list.size() != 3) {
            list = attentionService.findThreeUserInfo(userId);
        }
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/attention 14、关注or取消关注
     * @apiVersion 0.0.1
     * @apiName user.attention
     * @apiGroup user
     *
     * @apiDescription 关注or取消关注
     *
     * @apiParam   {Integer}   userId                 用户ID                                 (必填)
     * @apiParam   {Integer}   sourceId               目标用户ID                              (必填)
     * @apiParam   {Integer}   type                   类型，0=关注，1=取消关注，不填默认为0      (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/attention", method = RequestMethod.POST)
    public void attention(HttpServletResponse response, Integer userId, Integer sourceId, Integer type) {
        try {
            attentionService.iModifyAttentionInfo(userId, sourceId, type);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (AttentionNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_ATTENTION_NOT_FIND));
        } catch (AttentionExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_ATTENTION_EXIST));
        }
    }

    /**
     * @api {post} /api/user/list 15、用户列表（昵称搜索）
     * @apiVersion 0.0.1
     * @apiName user.list
     * @apiGroup user
     *
     * @apiDescription 用户列表
     *
     * @apiParam   {Integer}   userId                     用户Id
     * @apiParam   {String}    nickName                   用户昵称
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    用户ID
     * @apiSuccess {String}    list.nickName              姓名
     * @apiSuccess {String}    list.avatar                手机号
     * @apiSuccess {Integer}   list.regionId              所在地ID
     * @apiSuccess {String}    list.regionInfo            所在地名称
     * @apiSuccess {Integer}   list.isAttentionOther      我是否关注对方，0=否，1=是
     * @apiSuccess {Integer}   list.isAttentionMe         对方是否关注我，0=否，1=是
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "nickName" : "霍尊",
     *                  "avatar" : "http://www.qq.com",
     *                  "regionId" : 1,
     *                  "regionInfo" : "北京",
     *                  "isAttentionOther" : 0,
     *                  "isAttentionMe" : 0
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public void list(HttpServletResponse response, Integer userId, String nickName, Integer pageNum, Integer pageSize) {
        Page<UserInfoVo> page = userService.iPageByParams(userId, nickName, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/leaveList 16、留言列表
     * @apiVersion 0.0.1
     * @apiName user.leaveList
     * @apiGroup user
     *
     * @apiDescription 留言列表
     *
     * @apiParam   {Integer}   userId                     用户Id                                 （必填）
     * @apiParam   {Integer}   type                       类型，1，我的留言 2，别人对我的留言       （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    留言ID
     * @apiSuccess {String}    list.userId                留言人ID
     * @apiSuccess {String}    list.nickName              留言人昵称
     * @apiSuccess {String}    list.avatar                留言人头像
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.imageList             图片列表
     * @apiSuccess {String}    list.imageList.id          图片ID
     * @apiSuccess {String}    list.imageList.url         图片url
     * @apiSuccess {String}    list.createTime            留言时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "userId" : 1,
     *                  "nickName" : "张三",
     *                  "avatar" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "content" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "imageList" : [
     *                      {
     *                          "id" : 1,
     *                          "url" : "http://4.16.3.22:8080/images/cover.jpg"
     *                      }
     *                  ],
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/leaveList", method = RequestMethod.POST)
    public void leaveList(HttpServletResponse response, Integer userId, Integer type, Integer pageNum, Integer pageSize) {
        if (null == userId || null == type) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        Page<Comment> page = leaveMessageService.iPageForApp(userId, type, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "user", "sourceUser", "sourceId", "sourceType", "voiceTime", "isAdmin", "isTop", "cover", "title", "synopsis", "isRead");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/leave 17、给用户留言
     * @apiVersion 0.0.1
     * @apiName user.leave
     * @apiGroup user
     *
     * @apiDescription 给用户留言
     *
     * @apiParam   {Integer}   userId                 用户ID                                 (必填)
     * @apiParam   {Integer}   sourceId               目标用户ID                              (必填)
     * @apiParam   {String}    content                内容
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/leave", method = RequestMethod.POST)
    public void leave(HttpServletResponse response, Integer userId, Integer sourceId, String content, Integer imgNum/*, MultipartRequest multipartRequest*/) {
        try {
            userService.iAddLeave(userId, sourceId, content, imgNum/*, multipartRequest*/);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/comment 18、添加评论
     * @apiVersion 0.0.1
     * @apiName user.comment
     * @apiGroup user
     *
     * @apiDescription 添加评论
     *
     * @apiParam   {Integer}   userId                 用户ID                                                    (必填)
     * @apiParam   {Integer}   sourceId               目标ID                                                    (必填)
     * @apiParam   {Integer}   sourceType             目标类型，0=信件，1=纸条，2=广播，3=心事，4=兴趣圈，7=黑板     (必填)
     * @apiParam   {Integer}   type                   是否回复，0=否，不为0=回复对象ID，不填默认为0
     * @apiParam   {Integer}   voiceTime              语音长度
     * @apiParam   {Stream}    voice                  语音
     * @apiParam   {String}    content                内容
     * @apiParam   {Integer}   imgNum                 图片数量
     * @apiParam   {Stream}    image                  图片组
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/comment", method = RequestMethod.POST)
    public void comment(HttpServletResponse response, Integer userId, Integer sourceId, Integer sourceType, Integer type, Integer voiceTime, String content, Integer imgNum, MultipartRequest multipartRequest) {
        try {
            commentService.addComment(false, userId, sourceId, sourceType, type, voiceTime, content, imgNum, multipartRequest);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/user/buyList 19、我的购买列表
     * @apiVersion 0.0.1
     * @apiName user.buyList
     * @apiGroup user
     *
     * @apiDescription 我的购买列表
     *
     * @apiParam   {Integer}   userId                     用户Id                          （必填）
     * @apiParam   {Integer}   type                       类型，1=信纸，2=信封，3=邮票      （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    物品ID
     * @apiSuccess {Integer}   list.type                  类型，1=信纸，2=信封，3=邮票
     * @apiSuccess {String}    list.cover                 封面url
     * @apiSuccess {String}    list.content               内容url
     * @apiSuccess {String}    list.name                  名称
     * @apiSuccess {String}    list.num                   物品编号
     * @apiSuccess {Double}    list.money                 价格
     * @apiSuccess {String}    list.description           物品描述
     * @apiSuccess {String}    list.createTime            购买时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "type" : 3,
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "content" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "name" : "邮票",
     *                  "num" : "592-01",
     *                  "money" : 3.5,
     *                  "description" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/buyList", method = RequestMethod.POST)
    public void buyList(HttpServletResponse response, Integer userId, Integer type, Integer pageNum, Integer pageSize) {
        if (null == userId || null == type) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        Page<LetterAnnexSample> page = userService.iPageLetterAnnexByParams(userId, type, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "letterAnnexId");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/collectList 20、我的收藏列表
     * @apiVersion 0.0.1
     * @apiName user.collectList
     * @apiGroup user
     *
     * @apiDescription 我的收藏列表
     *
     * @apiParam   {Integer}   userId                     用户Id                                   （必填）
     * @apiParam   {Integer}   type                       类型，1=纸条，2=广播，3=心事，4=兴趣圈      （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list                       纸条列表
     * @apiSuccess {Integer}   list.id                    纸条ID
     * @apiSuccess {Integer}   list.paperId               信纸ID
     * @apiSuccess {Integer}   list.type                  类型，1=短叹，2=长吟
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.backgroundImage       背景图URL
     * @apiSuccess {Integer}   list.isTop                 是否置顶，0=否，1=是
     * @apiSuccess {Integer}   list.praiseNum             点赞数
     * @apiSuccess {Integer}   list.commentNum            评论数
     * @apiSuccess {Integer}   list.isPraise              是否点赞，0=否，1=是
     * @apiSuccess {Integer}   list.isCollect             是否收藏，0=否，1=是
     * @apiSuccess {Integer}   list.isAdmin               是否管理员发送，0=否，1=是
     * @apiSuccess {Integer}   list.userId                发送人ID
     * @apiSuccess {String}    list.nickName              发送人昵称
     * @apiSuccess {String}    list.avatar                发送人头像
     * @apiSuccess {Integer}   list.regionId              发送人所在地ID
     * @apiSuccess {String}    list.regionInfo            发送人所在地名称
     * @apiSuccess {String}    list.createTime            发送时间
     *
     * @apiSuccess {Object}    list                       广播列表
     * @apiSuccess {Integer}   list.id                    广播ID
     * @apiSuccess {Integer}   list.title                 标题
     * @apiSuccess {String}    list.url                   语音url
     * @apiSuccess {String}    list.duration              语音长度
     * @apiSuccess {Integer}   list.isAdmin               是否管理员发送，0=否，1=是
     * @apiSuccess {Integer}   list.isTop                 是否置顶，0=否，1=是
     * @apiSuccess {Integer}   list.praiseNum             点赞数
     * @apiSuccess {Integer}   list.commentNum            评论数
     * @apiSuccess {Integer}   list.isPraise              是否点赞，0=否，1=是
     * @apiSuccess {Integer}   list.isComment             是否评论，0=否，1=是
     * @apiSuccess {Integer}   list.isCollect             是否收藏，0=否，1=是
     * @apiSuccess {Integer}   list.userId                发送人ID
     * @apiSuccess {String}    list.nickName              发送人昵称
     * @apiSuccess {String}    list.avatar                发送人头像
     * @apiSuccess {Integer}   list.regionId              发送人所在地ID
     * @apiSuccess {String}    list.createTime            发送时间
     *
     * @apiSuccess {Object}    list                       心事列表
     * @apiSuccess {Integer}   list.id                    心事ID
     * @apiSuccess {String}    list.title                 标题
     * @apiSuccess {String}    list.cover                 封面url
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.openMoney             偷心金额
     * @apiSuccess {Integer}   list.isTop                 是否置顶，0=否，1=是
     * @apiSuccess {Integer}   list.praiseNum             点赞数
     * @apiSuccess {Integer}   list.commentNum            评论数
     * @apiSuccess {Integer}   list.isPraise              是否点赞，0=否，1=是
     * @apiSuccess {Integer}   list.isCollect             是否收藏，0=否，1=是
     * @apiSuccess {Integer}   list.isGet                 是否偷心，0=否，1=是
     * @apiSuccess {Integer}   list.isAdmin               是否管理员发送，0=否，1=是
     * @apiSuccess {Integer}   list.userId                发送人ID
     * @apiSuccess {String}    list.nickName              发送人昵称
     * @apiSuccess {String}    list.avatar                发送人头像
     * @apiSuccess {Integer}   list.regionId              发送人所在地ID
     * @apiSuccess {String}    list.regionInfo            发送人所在地名称
     * @apiSuccess {String}    list.createTime            发送时间
     *
     * @apiSuccess {Object}    list                       草丛列表
     * @apiSuccess {Integer}   list.id                    草丛ID
     * @apiSuccess {Integer}   list.title                 标题
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.synopsis              简介
     * @apiSuccess {Object}    list.imageList             图片列表
     * @apiSuccess {String}    list.imageList.url         图片url
     * @apiSuccess {String}    list.labels                标签名称，中间用英文逗号隔开
     * @apiSuccess {Integer}   list.isAdmin               是否管理员发布，0=否，1=是
     * @apiSuccess {Integer}   list.isTop                 是否置顶，0=否，1=是
     * @apiSuccess {Integer}   list.praiseNum             点赞数
     * @apiSuccess {Integer}   list.commentNum            评论数
     * @apiSuccess {Integer}   list.isPraise              是否点赞，0=否，1=是
     * @apiSuccess {Integer}   list.isComment             是否评论，0=否，1=是
     * @apiSuccess {Integer}   list.userId                发送人ID
     * @apiSuccess {String}    list.nickName              发送人昵称
     * @apiSuccess {String}    list.avatar                发送人头像
     * @apiSuccess {String}    list.createTime            发送时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "paperId" : 1,
     *                  "type" : 1,
     *                  "content" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "isTop" : 1,
     *                  "praiseNum" : 124,
     *                  "commentNum" : 20,
     *                  "isPraise" : 0,
     *                  "isCollect" : 0,
     *                  "isAdmin" : 0,
     *                  "userId" : 1,
     *                  "nickName" : "张三",
     *                  "avatar" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/collectList", method = RequestMethod.POST)
    public void collectList(HttpServletResponse response, Integer userId, Integer type, Integer pageNum, Integer pageSize) {
        if (null == userId || null == type) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        Map<String, Object> dataMap = new HashMap<>();

        switch (type) {
            case 1:
                // 纸条
                Page<Paper> paperPage = paperService.iPageForAppCollect(userId, pageNum, pageSize);
                dataMap = JsonUtil.fitting(paperPage);
                break;
            case 2:
                // 广播
                Page<Broadcast> broadcastPage = broadcastService.iPageForAppCollect(userId, pageNum, pageSize);
                dataMap = JsonUtil.fitting(broadcastPage);
                break;
            case 3:
                // 心事
                Page<Mind> mindPage = mindService.iPageForAppCollect(userId, pageNum, pageSize);
                dataMap = JsonUtil.fitting(mindPage);
                break;
            case 4:
                // 兴趣圈
                Page<Circle> circlePage = circleService.iPageForAppCollect(userId, "", pageNum, pageSize);
                dataMap = JsonUtil.fitting(circlePage);
                break;
        }

        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "user");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/praise 21、点赞or取消赞
     * @apiVersion 0.0.1
     * @apiName user.praise
     * @apiGroup user
     *
     * @apiDescription 给用户留言
     *
     * @apiParam   {Integer}   userId                 用户ID                                                    (必填)
     * @apiParam   {Integer}   sourceId               目标用户ID                                                (必填)
     * @apiParam   {String}    sourceType             目标类型，0=信件，1=纸条，2=广播，3=心事，4=兴趣圈，7=黑板     (必填)
     * @apiParam   {Integer}   type                   操作，1=赞，2=取消赞                                       (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/praise", method = RequestMethod.POST)
    public void praise(HttpServletResponse response, Integer userId, Integer sourceId, Integer sourceType, Integer type) {
        try {
            userService.iPraise(userId, sourceId, sourceType, type);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (PraiseNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_PRAISE_NOT_FIND));
        } catch (PraiseExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_PRAISE_EXIST));
        }
    }

    /**
     * @api {post} /api/user/collect 22、收藏or取消收藏
     * @apiVersion 0.0.1
     * @apiName user.collect
     * @apiGroup user
     *
     * @apiDescription 收藏or取消收藏
     *
     * @apiParam   {Integer}   userId                 用户ID                                             (必填)
     * @apiParam   {Integer}   sourceId               目标用户ID                                          (必填)
     * @apiParam   {String}    sourceType             目标类型，1=纸条，2=广播，3=心事，4=兴趣圈            (必填)
     * @apiParam   {Integer}   type                   操作，1=收藏，2=取消收藏                             (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/collect", method = RequestMethod.POST)
    public void collect(HttpServletResponse response, Integer userId, Integer sourceId, Integer sourceType, Integer type) {
        try {
            userService.iCollect(userId, sourceId, sourceType, type);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (CollectNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_COLLECT_NOT_FIND));
        } catch (CollectExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_COLLECT_EXIST));
        }
    }

    /**
     * @api {post} /api/user/address/defaultInfo 23、用户默认收货地址
     * @apiVersion 0.0.1
     * @apiName user.defaultInfo
     * @apiGroup user
     *
     * @apiDescription 用户默认收货地址
     *
     * @apiParam   {Integer}   userId                            用户Id                   （必填）
     *
     * @apiSuccess {Object}    addressInfo
     * @apiSuccess {Integer}   addressInfo.id                    地址ID
     * @apiSuccess {String}    addressInfo.userName              姓名
     * @apiSuccess {String}    addressInfo.mobile                手机号
     * @apiSuccess {Integer}   addressInfo.regionId              所在地ID
     * @apiSuccess {Integer}   addressInfo.regionInfo            所在地名称
     * @apiSuccess {String}    addressInfo.description           详细地址
     * @apiSuccess {Integer}   addressInfo.isDefault             是否默认地址，0=否，1=是
     * @apiSuccess {Integer}   addressInfo.createNum             创建时间
     * @apiSuccess {Integer}   addressInfo.updateNum             修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "addressInfo": {
     *              "id" : 1,
     *              "userName" : "霍尊",
     *              "mobile" : "15963665254",
     *              "regionId" : 1,
     *              "regionInfo" : "北京",
     *              "description" : "东大街6305号",
     *              "isDefault" : 1,
     *              "createTime" : "1476843673494",
     *              "updateNum" : "1476843673494"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/address/defaultInfo", method = RequestMethod.POST)
    public void defaultInfo(HttpServletResponse response, Integer userId) {
        if (null == userId) {
            String result = JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM));
            WebUtil.printApi(response, result);
            return;
        }

        UserAddress address = userAddressService.findDefaultByUserId(userId);
        String result = JsonUtil.obj2ApiJson(Result.successInfoApi(null == address ? new HashMap<>() : address, "addressInfo"), "user", "region");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/user/deleteInfo 24、删除我的锦囊
     * @apiVersion 0.0.1
     * @apiName user.deleteInfo
     * @apiGroup user
     *
     * @apiDescription 删除我的锦囊
     *
     * @apiParam   {Integer}   sourceId               目标用户ID                                  (必填)
     * @apiParam   {String}    sourceType             目标类型，1=纸条，2=广播，3=心事，4=兴趣圈     (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/deleteInfo", method = RequestMethod.POST)
    public void deleteInfo(HttpServletResponse response, Integer sourceId, Integer sourceType) {
        try {
            userService.deleteInfo(sourceId, sourceType);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        }
    }

    /**
     * @api {post} /api/user/recordMoney 25、充值
     * @apiVersion 0.0.1
     * @apiName user.recordMoney
     * @apiGroup user
     *
     * @apiDescription 充值
     *
     * @apiParam   {Integer}   userId               用户ID                             (必填)
     * @apiParam   {Double}    money                充值金额                           (必填)
     * @apiParam   {Integer}   platform             充值平台，1=微信，2=支付宝           (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "userMoneyId" : 1
     *      }
     * }
     */
    @RequestMapping(value = "/recordMoney", method = RequestMethod.POST)
    public void recordMoney(HttpServletResponse response, Integer userId, Double money, Integer platform) {
        try {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successInfoApi(userService.recordMoney(userId, money, platform), "userMoneyId")));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        }
    }

    /**
     * @api {post} /api/user/pay 26、用户使用账户余额支付
     * @apiVersion 0.0.1
     * @apiName user.pay
     * @apiGroup user
     *
     * @apiDescription 用户使用账户余额支付
     *
     * @apiParam   {Integer}   userId                用户Id                                                      （必填）
     * @apiParam   {Integer}   sourceId              目标ID                                                      （必填）
     * @apiParam   {Integer}   sourceType            类型，1=偷心，2=写纸条，3=写信，4=拆信，5=收信                  （必填）
     * @apiParam   {Double}    money                 金额                                                        （必填）
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    public void pay(HttpServletResponse response,
                    Integer userId,
                    Integer sourceId,
                    Integer sourceType,
                    Double money) {
        try {
            if (null == userId || null == sourceId || null == sourceType) {
                WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
                return;
            }

            switch (sourceType) {
                case 1:
                    // 偷心
                    mindService.changeMoneyStatusByMoney(sourceId, money);
                    break;
                case 2:
                    // 写纸条
                    paperService.changeMoneyStatusByMoney(sourceId, money);
                    break;
                case 3:
                    // 写信
                    letterService.sendLetterInfo(userId, sourceId, money);
                    break;
                case 4:
                    // 拆信
                    letterService.payLetterInfo(userId, sourceId);
                    break;
                case 5:
                    // 收信
                    letterService.getLetterInfo(userId, sourceId, money);
                    break;
            }
            String result = JsonUtil.obj2ApiJson(Result.successApi());
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (LetterNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_LETTER_NOT_FIND));
        } catch (MoneyShortException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MONEY_SHORT));
        } catch (LetterMoneyExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_LETTER_MONEY_EXIST));
        }
    }
}
